package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.LogAnno;
import com.example.common.Result;
import com.example.common.enums.LogType;
import com.example.pojo.entity.Department;
import com.example.service.DepartmentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author ding
 * @since 2024/6/13
 */
@RestController
@RequestMapping("/department")
@Api(tags = "部门相关接口")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

//    @PreAuthorize("hasAuthority('DEPARTMENT_PAGEQUERY')")
    @GetMapping("/selectPage")
    public Result selectPage(String name,
                             String projectName,
                             String order,
                             @RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize){
        Page<Department> page = departmentService.selectPage(name,projectName,order,pageNum,pageSize);
        return Result.success(page);
    }

    @PutMapping("/update")
//    @PreAuthorize("hasAuthority('DEPARTMENT_EDIT')")
    @LogAnno(title = "部门管理", type = LogType.UPDATE)
    public Result update(@RequestBody Department department){
        departmentService.update(department);
        return Result.success();
    }

    @LogAnno(title = "部门管理", type = LogType.DELETE)
//    @PreAuthorize("hasAuthority('DEPARTMENT_DELETE')")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        departmentService.deleteById(id);
        return Result.success();
    }

    @LogAnno(title = "部门管理", type = LogType.ADD)
//    @PreAuthorize("hasAuthority('DEPARTMENT_ADD')")
    @PostMapping("/add")
    public Result add(@RequestBody Department department){
        departmentService.addDepartment(department);
        return Result.success();
    }

}
